package cn.hbwe.controller;


import cn.hbwe.pojo.entity.Booking;
import cn.hbwe.pojo.entity.Patient;
import cn.hbwe.pojo.entity.Schedule;
import cn.hbwe.pojo.vo.BookingVo;
import cn.hbwe.service.IBookingService;
import cn.hbwe.service.IDoctorService;
import cn.hbwe.service.IScheduleService;
import cn.hbwe.util.PageVO;
import cn.hbwe.util.Result;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 7组
 * @since 2023-10-18
 */
@RestController
@RequestMapping("/booking")
@Api(tags = "预约信息操作")
@CrossOrigin
public class BookingController {

    @Autowired
    private IBookingService bookingService;

    @Autowired
    private IScheduleService scheduleService;
    /**
     * 病人预约医生
     * @param booking
     * @return
     */
    @ApiOperation("病人预约医生")
    @PostMapping("/save")
    public Result<String> booking(@RequestBody Booking booking) {
        bookingService.booking(booking);
        return Result.success("预约成功");
    }

    /**
     * 根据医生id查看预约信息
     * @param id
     * @return
     */
    @ApiOperation("根据医生id查看预约信息")
    @GetMapping("/getBooking/{id}")
    public Result<List<BookingVo>> getBooking(@PathVariable Integer id) {
        List<BookingVo> bookings = bookingService.getBookingByDoctorId(id);
        return Result.success(bookings);
    }

    @PostMapping("/bmodify")
    @ApiOperation("修改用户信息")
    public Result<Booking> modifyPatient(@RequestBody Booking booking) {

        bookingService.updateById(booking);
        return Result.success(booking);

    }



    /**
     * 根据科室id查询医生信息
     * @param Id
     */
    @ApiOperation("根据用户账号查询用户信息")
    @GetMapping("/getScheduleId/{Id}")
    public Result<List<Schedule>> getByScheduleId(@PathVariable int Id) {
        List<Schedule> schedule = scheduleService.getScheduleId(Id);
        System.out.println(schedule);
        return Result.success(schedule);
    }


    @ApiOperation("根据患者id查看预约记录")
    @GetMapping("/page/{currentPage}/{pageSize}")
    public Result<PageVO<BookingVo>> getPage(@PathVariable Long currentPage, @PathVariable Long pageSize, Integer patientId) {
        PageVO<BookingVo> page = bookingService.getPage(currentPage, pageSize, patientId);
        return Result.success(page);
    }


    //---------y---------------
    //更改就诊状态
    //看病中
    @GetMapping("/updateBookingStateTwo/{bookingId}")
    public void updateBookingStateTwo(@PathVariable("bookingId") int bookingId){

        bookingService.updateBookingStateTwo(bookingId);

    }
    //就诊结束
    @GetMapping("/updateBookingStateThree/{bookingId}")
    public void updateBookingStateThree(@PathVariable("bookingId") int bookingId){

        bookingService.updateBookingStateThree(bookingId);

    }

    //根据医生ID查看预约
    /**
     * 根据医生id查看病历
     * @param currentPage
     * @param pageSize
     * @param doctorId
     * @return
     */
    @ApiOperation("根据医生id查看病历")
    @GetMapping("/page2/{currentPage}/{pageSize}")
    public Result<PageVO<BookingVo>> getPageByDoctorId(@PathVariable Long currentPage,@PathVariable Long pageSize,Integer doctorId) {
        PageVO<BookingVo> page = bookingService.getPageByDoctorId(currentPage, pageSize, doctorId);
        return Result.success(page);
    }

}
